import $service from '../../../../service.js';
var log_id;
var that;
Page({
    data:{
       isshow: false,
       doctorMap:{},
       inquiryMap:{},
       bz:''
    },
    onLoad(e){
       log_id = e.log_id;
    },
    onShow(){
        that = this.data
        this.publicUtil_getInquiryLogDetails()
    },
    //数据
    publicUtil_getInquiryLogDetails:function(){
        var jsonData ={
            "is_receive":"1",
            "log_id" : log_id
        }
        var jsonAjax = {
            "url": "publicUtil_getInquiryLogDetails.do",
            "jsonData": jsonData,
        }
        $service.getAjaxData(jsonAjax, this.publicUtil_getInquiryLogDetails_back);
    },
    //回调
    publicUtil_getInquiryLogDetails_back: function(jsonBack){
         var data=$service.strToJson(jsonBack.data).data;
         that.inquiryMap= data.inquiryMap; //患者信息
         var inquiryMap= data.inquiryMap
         that.doctorMap = data.doctorMap; //医生信息
         if (!$service.isUndefinedAndEmpty(inquiryMap.lof_diagnosis)) {
             var lof_diagnosis = '';
             var lof_diagnosis2 = '';
             var numC =0
             var lofdiagnosislist = inquiryMap.lof_diagnosis.split(",")
             for (var i = 0; i < lofdiagnosislist.length; i++) {
                 var index = lofdiagnosislist[i].indexOf('自定义诊断');
                 if (index > -1) {
                     lof_diagnosis2 += lofdiagnosislist[i] + ",";
                 } else {
                     numC++
                     lof_diagnosis += "(" + numC + ")" + lofdiagnosislist[i] + ",";
                 }
             }
             inquiryMap.diagnosisMap = lof_diagnosis + lof_diagnosis2;
             inquiryMap.diagnosisMap = inquiryMap.diagnosisMap.substring(0, inquiryMap.diagnosisMap.length - 1);
         } else {
             inquiryMap.diagnosisMap =''
         }
         this.setData({
             inquiryMap: that.inquiryMap,
             doctorMap: that.doctorMap
             
         })
        
    },
    tapactive(e){
        console.log(e)
        var index = e.currentTarget.dataset.index;
        if(index == 1){
            this.data.active = true
        }else{
            this.data.active = false
        }
        this.setData({
            active : this.data.active
        })
    },
    //监听input框
    inputChange(e){
        console.log(e)
       var index = e.currentTarget.dataset.index;
       if(index == 1){
           that.doctorMap.department_name = e.detail.value
       }else{
           that.bz = e.detail.value
       }
       this.setData({
           doctorMap : that.doctorMap,
           bz:that.bz
       })
    },
    //生成住院建议书
    qr_btn(){
        if($service.isUndefinedAndEmpty(that.inquiryMap.log_main_suit)){
            $service.showToast("请先输入主诉")
            return;
        }
        if($service.isUndefinedAndEmpty(that.inquiryMap.diagnosisMap) ){
            $service.showToast("请先输入诊断")
            return;
        }
        if($service.isUndefinedAndEmpty(that.doctorMap.department_name)){
            $service.showToast('请输入科室')
            return
        }
        var jsonData={
            "hospital_id" : that.doctorMap.hospital_id,
            "log_id" : log_id,
            "user_type" :that.inquiryMap.join_type,
            "user_id" : that.inquiryMap.join_id,
            "inquiry_patient_id" : that.inquiryMap.inquiry_patient_id,
            "doctor_id" : that.doctorMap.doctor_id,
            "hospitalization_hospital" : that.doctorMap.hospital_styymc,
            "hospitalization_department": that.doctorMap.department_name,
            "bz" :that.bz
        } 
        var jsonAjax = {
            "url": "doctorSide_personal_inquiry_addHospitalization.do",
            "jsonData": jsonData,
        }
        $service.getAjaxData(jsonAjax, this.doctorSide_personal_inquiry_addHospitalization_back);
    },
    doctorSide_personal_inquiry_addHospitalization_back(jsonBack){
        var jsonInfo = $service.strToJson(jsonBack.data);
        var data = jsonInfo.data;
        if(jsonInfo.code == '200'){
            var selToID='';
            if(that.inquiryMap.join_type == 1){
                 selToID = "U" + that.inquiryMap.join_id
            }else{
                  selToID = "S" + that.inquiryMap.join_id
            }
            var sendSystemMessageMsgText = '医生已下达住院建议书'
            wx.txTic.sendCustomMessage(selToID,6)
            wx.txTic.sendSystemMessageMsg(selToID,sendSystemMessageMsgText);
            $service.showToast('生成成功');
            setTimeout(function(){
                wx.navigateBack({
                    delta: 1
                });
            },600)
            
        }
    },
    gotodetalis(e){
        var index = e.currentTarget.dataset.index;
        if(index == 0 || index == 1 || index == 2 || index == 3 ||index == 4 ){//0过敏史 1 主诉 2现病史 3既往史 4诊断
            $service.openPage('../index_diagnosis/index_diagnosis?inquiryMap=' + $service.jsonToStr(that.inquiryMap) +'&index='+ index)
        }
    }
})